<?php 
include 'map/map_control_listing.php';
include 'map/map_control_script.php';


$oid = $_GET['listing_id'];
$mquery = "select p.* from PROPERTIES p where p.OID = '".$oid."'";
$mresult = mysql_query($mquery) or die ("SQL Error".mysql_error());
$prow = mysql_fetch_assoc($mresult);
if($prow['UNITFLOORNUM'] !='')
{
	$unit = " ".$prow['UNITFLOORNUM'];
}
else
{
	$unit = '';
}
$full_address = $prow['STREETNUM']." ".$prow['STREETDIR']." ".$prow['STREETNAME']." ".$prow['STREETSUFFIX']."".$unit.", ".$prow['CITY']." ".$prow['STATE']." ".$prow['ZIPCODE'];

$query = "Select * from VT_Config where Listing_ID = '".$oid."'";
$result = mysql_query($query) or die ("SQL Error".mysql_error());
$rowv = mysql_fetch_assoc($result);
	
$mquery = "select p.* from PROPERTIES p where p.OID = '".$oid."'";
$mresult = mysql_query($mquery) or die ("SQL Error".mysql_error());

$cquery = "select * from VT_Config where Listing_ID = '".$oid."'";
$cresult = mysql_query($cquery) or die ("SQL Error".mysql_error());
$crow = mysql_fetch_assoc($cresult);

$disp_zesti = $crow['disp_zesti'];
$disp_zcomps = $crow['disp_zcomps'];
$disp_zindex = $crow['disp_zindex'];
?>

<table bgcolor="#666666" style=" color:#999999; border-top:1px solid black; border-bottom:1px solid black; font-family:Arial, Helvetica, sans-serif" align="center" width="100%" border="0" cellspacing="0" cellpadding="0">
			<TR>
				<TD align="center" style="padding:2px 0px 2px 20px; height:20px;">
					<table width="825" border="0" cellspacing="1" cellpadding="1">
						  <tr>
							<td align="left" style="color:#FFFFFF; font-size:18px;">
							<?php echo $full_address ?> | 
							Asking Price: $<?php echo number_format($prow['LISTPRICE'], 0) ?>
							</td>
						  </tr>
						</table>
				</TD>
			</TR>
		</Table>


<center>
<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>

<!--Main Page-->



<script src="ajax_image_js.js" type="text/javascript"></script>
<!--<script src="map/map_control_script.js" type="text/javascript"></script>
--><script type="text/javascript" src="map/Neighborhood_ajax_map.js"></script>
<script type="text/javascript" src="api/listings.js"></script>
<script src="http://maps.google.com/maps?file=api&v=2&key=<?php echo SITE_KEY ?>" type="text/javascript"></script>
<script type="text/javascript">
var map;
var comps_by_addr, disp_zillowcomps;


function Onload()
{

	disp_zillowcomps = 1;
	disp_zestimate = 1;
	disp_zindex = 1;

  <?php 
   global $city, $state,$zipcode, $address;
   if($row = mysql_fetch_assoc($mresult))
	{
		echo "latitude =". $row['LATITUDE'].";";
		echo "longitude =". $row["LONGITUDE"].";";
		echo "city =". "'".$row["CITY"]."'".";";
		echo "state=". "'".$row["STATE"]."'".";";
		echo "zipcode =". $row["ZIPCODE"].";";
		echo "title =". "'".$row["TITLE"]."'".";";
		//echo "dispTitle = Truncatestr(title,40,'...');"; 
		$city = $row["CITY"];
		$state = $row["STATE"];
		$zipcode = $row["ZIPCODE"];
		
		echo "title ="."\"".str_replace("\""," ",$row["TITLE"])."\"".";";

		
		if($row["STREETNAME"])
		  echo "streetname=". "'".$row["STREETNAME"]."'".";";
		 else
		  echo "streetname = null".";";
		  
		if($row["STREETNUM"])
		  echo "streetnum=". "'".$row["STREETNUM"]."'".";";
		else
		  echo "streetnum = null".";";
		  
		if($row["STREETSUFFIX"])
		  echo "streetsfx=". "'".$row["STREETSUFFIX"]."'".";";
		else
		  echo "streetsfx = null".";";
		  
		  
		$address = $row["STREETNUM"]." ".$row["STREETNAME"]." ".$row["STREETSUFFIX"];


		if($row["BEDS"])
		 echo "beds =". $row["BEDS"].";";
		else
		 echo "beds = 0".";";
		 
		if($row["BATHSTOTAL"])
		 echo "baths =". $row["BATHSTOTAL"].";";
		else
		 echo "baths = 0".";";

		if($row["SQFTTOTAL"])
		 echo "sqft =". $row["SQFTTOTAL"].";";
		else
		 echo "sqft = 0".";";

	}
	
	if($disp_zcomps)
		echo "disp_zillowcomps=1;";
	else
		echo "disp_zillowcomps=0;";

	if($disp_zesti)
		echo "disp_zestimate=1;";
	else
		echo "disp_zestimate=0;";

	if($disp_zindex)
		echo "disp_zindex=1;";
	else
		echo "disp_zindex=0;";

		
	
	?>
	
/*	if(streetnum && streetname && streetsfx)
	{
	addr = streetnum+ " " + streetname + " " + streetsfx;
	comps_by_addr = 1;
	}
	else
	{
	addr = null;
	comps_by_addr = 0;

	}
*/	

	//addr = streetnum+ " " + streetname + " " + streetsfx;
	//comps_by_addr = 1;

	if(streetnum && streetname && streetsfx)
	{
	addr = streetnum+ " " + streetname + " " + streetsfx;
	comps_by_addr = 1;
	}
	else
	{
	if(streetnum && streetname)
	{
	addr = streetnum+ " " + streetname;
	comps_by_addr = 1;
	}
	else
	{
	addr = null;
	comps_by_addr = 0;

	}
	}


	if(disp_zillowcomps == 1)
	{
	map_control_load(latitude, longitude, zipcode,title, city, state);
	if(comps_by_addr)
	{
	Comp_Chk_Box = document.getElementById("comp_ckbx");
	Comp_Chk_Box.checked = "true";

	//document.getElementById("comp_title").innerHTML = "Nearby Recent Sales";
	
	document.getElementById("comp_title").innerHTML = "Comparable Sales";


//	document.getElementById("comp_title").innerHTML += "<a target=_blank href=\'http://www.zillow.com/\'><img src='images/other_logos/zillowlogo_150x40.gif' width=150 height=40 border=0  ></a>";


	document.getElementById("comp_title").style.display="";
	document.getElementById("CompSchool").style.display="";

	get_comparables_by_addr(addr, latitude,longitude,title,zipcode,"CompSchool",state,city, beds, baths, sqft);
	}
	else
	{
	//document.getElementById("comp_title").innerHTML = "Nearby Recent Sales";
	
//	document.getElementById("comp_title").innerHTML = "Comparable Sales" + "&nbsp" + "&nbsp"+ "<a target=_blank href=\'http://www.zillow.com/\'><img src='images/other_logos/zillowlogo_150x40.gif' width=150 height=40 border=0  ></a>";
	
	document.getElementById("comp_title").innerHTML = "Comparable Sales";
	
//	document.getElementById("comp_title").innerHTML += "<a target=_blank href=\'http://www.zillow.com/\'><img src='images/other_logos/zillowlogo_150x40.gif' width=150 height=40 border=0  ></a>";

	
	document.getElementById("comp_title").style.display="";
	document.getElementById("CompSchool").style.display="";

	get_comparables(latitude,longitude,title,zipcode,"CompSchool",state,city, beds, baths, sqft);

	}
	} //if disp_zillowcomps


		//document.getElementById("prop_val_hist").innerHTML = "TEST";


   //map_control_load(latitude, longitude, zipcode,title);
}


</script>

<style type="text/css">
<!--
.style1 {
	color: #FF9900;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
}
.style2 {font-family: Arial, Helvetica, sans-serif}
.style3 {
	color: #FF9900;
	font-family: Arial, Helvetica, sans-serif;
	font-size:12px;
	font-weight: bold;
}

-->
</style>

<CENTER>
<table style="border-left:0px solid black; border-right:0px solid black;" border="0" cellspacing="0" cellpadding="0">
  
 <TR>
 	<TD><BR></TD>
 </TR>
 
  <TR>
  	<TD valign="top">
		<table style="padding-left:0px;" width="100%" border="0" cellspacing="0" cellpadding="0">
		
			 <tr>
    <td style="border:0px solid #CCCCCC;" valign="top">
	<!--main body-->
	<table width="800" border="0" cellspacing="0" cellpadding="0" style="padding-left:0px; ">
	 	<TR>
			<TD width="800" style="padding-left:0px; color:black; background-image:url(ajaxtabs/lb_bg.jpg); background-repeat:no-repeat; background-position:center;" height=35px colspan="3" bgcolor="white" align="left">
			<span style="padding-left:15px;"><img src=ajaxtabs/printer.gif align="absmiddle"> <a target="_blank" style="color:black; text-decoration:none" href=print_listing.php?listing_id=<?php echo $oid ?>>Printer Friendly Version</a> | 
			<img src = <?php echo SITE_ROOT_URL?>images/email.gif align="absmiddle"> <a style="color:black; text-decoration:none" href=email_friend.php?listing_id=<?php echo $oid ?>>Email to Friend</a>
			</span>
			</TD>
		  </TR>
	  <tr>
		<td width="420" valign="top" style="padding:0px;" align="left">
<?php 
	
	$mquery = "select * from Listing_Images where Listing_ID = '".$oid."' and Main_Photo = '1'";
	$mresult = mysql_query($mquery) or die ("SQL Error".mysql_error());
	if($mrow = mysql_fetch_assoc($mresult))
	{
	
		list($width_orig, $height_orig, $image_type) = getimagesize(ABS_PATH.'listing_images/resize_'.$mrow['Path']);
		if($width_orig > $height_orig)
		{
			//this picture is a landscape
			$width = 400;
			$height = ($width/$width_orig)*$height_orig;
		}
		else
		{
			$height = 400;
			$width = ($height/$height_orig)*$width_orig;
		}
		$main_image = SITE_ROOT_URL."../listing_images/resize_".$mrow['Path'];
	}
	else
	{
		list($width_orig, $height_orig, $image_type) = getimagesize(ABS_PATH.'listing_images/no_photo.gif');
		if($width_orig > $height_orig)
		{
			//this picture is a landscape
			$width = 400;
			$height = ($width/$width_orig)*$height_orig;
		}
		else
		{
			$height = 400;
			$width = ($height/$height_orig)*$width_orig;
		}
		$main_image = SITE_ROOT_URL.'../listing_images/no_photo.gif';
	}																				

	?>
	<table width="100%" height='305px' border="0" cellspacing="0" cellpadding="0">
			  <tr>
				<td valign="top" height='305px' style="padding:2px;"><div align=center id='main_image' style="border:0px solid black; padding:0px;"><img src='<?php echo $main_image?>' width = '<?php echo $width ?>' height='<?php echo $height ?>'></div></td>
			  </tr>
			  <tr>
				<td width="100%">
				<DIV>
				<?
				$mquery2 = "select * from Listing_Images where Listing_ID = '".$oid."' and Type = 'IMAGE'";
				$mresult2 = mysql_query($mquery2) or die ("SQL Error".mysql_error());
				while($mrow2 = mysql_fetch_assoc($mresult2))
				{
					?>
					<a href=javascript:; onclick="get_image('<?php echo $mrow2['Path'] ?>')"><img width=51 height=38 style="border:1px solid black;" src=<?php echo SITE_ROOT_URL."../listing_images/t_".$mrow2['Path'] ?>></a>
					<?
				}
				?>
				</DIV>
				<Br>
			<div id=listing_column_header><strong>Description</strong></div>			
			<div style="padding-right:10px; "><?php echo $row['REMARKS'] ?></div><BR />
			<?php
			$asql = "Select * from Users u inner join Prop_Owner_Con c on c.Owner = u.ID where c.Prop_OID = '".$oid."'";
			$aresult = mysql_query($asql) or die ("SQL Error".mysql_error());
			$arow=mysql_fetch_assoc($aresult);
			?>
			<DIV style="padding-top:10px;">
			<div style="float:left">
			<?php if ($arow['Image']!='')
			{ ?>
			<img src='<?php echo SITE_ROOT_URL?>user_images/t75_<?php echo $arow['Image'] ?>'>
			<?
			}
			else
			{
				?>
				<?
			}
			?>
			</div>
			
			<div style="float:left; padding-left:5px;">
			<div><strong><?php echo $arow['First_Name'] ?> <?php echo $arow['Last_Name'] ?></strong></div>
			<div>Phone: <?php echo $arow['Phone'] ?></div>
			<div>Email: <a href=mailto:<?php echo $arow['Email'] ?>><?php echo $arow['Email'] ?></a></div>
			<div>Website: <a target="_blank" href=http://<?php echo $arow['Website'] ?>><?php echo $arow['Website'] ?></a></div>
			
			<div align="right" style="padding:5px;">
			<?php if ($arow['Company_Logo']!='')
			{ ?>
			<img src='<?php echo SITE_ROOT_URL?>user_images/t_<?php echo $arow['Company_Logo'] ?>'>
			<?
			}
			else
			{
				?>
				<?
			}
			?>
			
			
			</div>
			</div>
			</div>

			
				<!--<div><a target="_blank" href=http://local.live.com/default.aspx?cp=<?php //echo $row['LONGITUDE'] ?>~<?php//echo $row['LATITUDE'] ?>&lvl=1scene=3050&style=o&v=2>Bird's Eye View</a></div>-->
				</td>
			  </tr>
			</table>
		</td>
		<td width="*" valign="top" align="left" id=listing_middle_column>
		<!--main content-->
			<div id=listing_column_header><strong>Asking Price: </strong>$<?php echo number_format($row['LISTPRICE'], 0) ?></div>
			
			<div><?php echo ($row['BEDS'])? "Beds: ".$row['BEDS']:"" ?></div>
			<div><?php echo ($row['BATHSTOTAL'])? "Baths: ".$row['BATHSTOTAL']:"" ?></div>
			<div><?php echo ($row['SQFTTOTAL'])? "SQFT: ".number_format($row['SQFTTOTAL'], 0):"" ?></div>
			<div><?php echo ($row['ASSOCFEE']!='0.00')? "HOA: $".$row['ASSOCFEE']:"" ?></div>
			<div><?php echo ($row['PARKINGCOVERED'])? "Parking: ".$row['PARKINGCOVERED']:"" ?></div>
			<div><?php echo ($row['YEARBUILT'])? "Year Built: ".$row['YEARBUILT']:"" ?></div>
			<div><?php echo ($row['MLSNUM'])? "MLSNUM: ".$row['MLSNUM']:"" ?></div>
			<Br>
			<!-- moved above
			<div id=listing_column_header><strong>Description</strong></div>			
			<div style="padding-right:10px; "><?php //echo $row['REMARKS'] ?></div><BR />
			-->
			
			<?php if ($row['IVR'] != ''){ ?>
			<div align="left" style="font-size:20px; color:#CC0000"><strong>24 HR Recorded Information</strong></div>
			<DIV align=left style="font-size:16px;"><img src=ajaxtabs/phone.gif align="absmiddle"> <strong><?php echo $row['IVR'] ?></strong></div>
			<DIV style="padding-bottom:20px;"></DIV>
			<?php }?>

			
			
			<?php 
			$oquery = "select * from Events where Listing_ID = '".$oid."' and Event_Date > curdate()";
			$oresult = mysql_query($oquery) or die ("SQL Error".mysql_error());
			if(mysql_num_rows($oresult))
			{
			?>
			<div id=listing_column_header>Open Houses</div>
			
			<div style="padding-bottom:20px;">
			<?
				while($orow = mysql_fetch_assoc($oresult))
				{
					?>
					<div style="padding:5px;">
					<DIV><strong><?php echo $orow['Title'] ?></strong></DIV>
					<DIV><strong><?php echo date('F j, Y', strtotime($orow['Event_Date'])) ?></strong></DIV>
					<DIV><strong>From:</strong> <?php echo $orow['Time_From'] ?> to <?php echo $orow['Time_To'] ?> <?php echo $orow['Time_Fix'] ?></DIV>
					</div>
					<?
				}
			}
			?>
			</div>
			
			<div>
			<?
			if($rowv['Doc_Group']!=0)
			{
			$doc_download = "<table width='100%' bgcolor=white cellspacing='1' cellpadding='1' border='0'style='border: 0px solid black;'>\n<tr>\n<td colspan='3' style='color: Black;'><strong>Download More Information</strong></td>\n</tr>\n";
			
			$db=mysql_connect("localhost","realiven_crm","i8itall") or die(mysql_error());
			mysql_select_db('realiven_crm',$db) or die(mysql_error());
			
			$sqld = "Select document_ids, group_id from document_grps where group_id = '".$rowv['Doc_Group']."'";
			$resultd = mysql_query($sqld) or die ("SQL Error".mysql_error());
			$rowd=mysql_fetch_assoc($resultd);
			
			$doc_id = explode(",", $rowd['document_ids']);
			foreach($doc_id as $id)
				{
					$dsql = "Select d.document_name, d.id from documents d where created_by = '".$arow['ID']."' and id = '".$id."'";
					$dresult = mysql_query($dsql) or die ("SQL Error".mysql_error());
					$drow=mysql_fetch_assoc($dresult);
					
					
						 		$doc_download .= "<tr>\n";
                                $doc_download .= "<td width='5%' align='left'><a href='http://www.realivent.com/crm/download_groups_poster.php?group_id=".$rowd['group_id']."' target='_blank'><img border='0' src='ajaxtabs/page_white_acrobat.gif'/></a></td>\n";
                                $doc_download .= "<td width='95%'><a href='http://www.realivent.com/crm/download_groups_poster.php?group_id=".$rowd['group_id']."' target='_blank'>".$drow['document_name']."</a></td>\n";
                                $doc_download .= "</tr>\n";
					

				}
				$doc_download .= "</TABLE><hr>";

			}
			echo $doc_download;
			?>
			</div>

			<!--<div id=listing_column_header>Offered By</div>-->
			
					
			<?php 
			/* agent information */

			?>
		</td>
	</table>
	<TABLE width="100%">
		<TR>
			<TD style="width:100%; padding-left:30px; border-top:1px solid #CCCCCC; border-bottom:1px solid #CCCCCC;" align="center">
			
				<?php include(ABS_PATH.'feature_control.php'); 
				get_features($oid);
				?>
			
			</TD>
		</TR>
	</TABLE>
	<TABLE>
	<TR>
	<?php
if($disp_zesti)
{
?>
<TD colspan="2" style="color:#00CC33; font-size:16px; font-family:Arial, Helvetica, sans-serif; font-weight:bold;" align='right'>Value Estimate: <script type="text/javascript" src="<?php echo SITE_ROOT_URL?>map/onboard/zillow_example.php?addr=<?php echo $address ?>&city=<?php echo $city ?>&state=<?php echo $state ?>&zip=<?php echo $zipcode ?>"> </script></TD>
<TD colspan="1" align="right"><a target=_blank href=\"http://www.zillow.com/\"><img src='<?php echo SITE_ROOT_URL?>images/other_logos/zillowlogo_150x40.gif' width=150 height=40 border=0/></TD>
<?
}
else if($disp_zindex)
{
?>
<TD colspan="2" style="color:#00CC33; font-size:16px; font-family:Arial, Helvetica, sans-serif; font-weight:bold;" align='left'>Valuation History For:</TD>
<TD colspan="1" align="right"><a target=_blank href=\"http://www.zillow.com/\"><img src='<?php echo SITE_ROOT_URL?>images/other_logos/zillowlogo_150x40.gif' width=150 height=40 border=0/></TD>
<?
}
?>
</TR>

<?php
if($disp_zindex)
{
?>
<TR><TD style=' background:#FEF9E4; color:#00CC33; font-size:16px; font-family:Arial, Helvetica, sans-serif; font-weight:bold;' align='center'><?php echo $row['ZIPCODE'] ?></TD><TD style=' background:#FEF9E4; color:#00CC33; font-size:16px; font-family:Arial, Helvetica, sans-serif; font-weight:bold;' align='center'><?php echo $row["CITY"] ?></TD><TD style=' background:#FEF9E4; color:#00CC33; font-size:16px; font-family:Arial, Helvetica, sans-serif; font-weight:bold;' align='center'><?php echo $row["STATE"] ?></TD></TR>


<!--<TR><TD style=' background:#FEF9E4; color:#00CC33; font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:bold;' align='center'>Valuation History For:<?php echo $address ?></TD><TD style=' background:#FEF9E4; color:#00CC33; font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:bold;' align='center'>Valuation History For:<?php echo $row['ZIPCODE'] ?></TD><TD style=' background:#FEF9E4; color:#00CC33; font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:bold;' align='center'>Valuation History For:<?php echo $row["CITY"] ?></TD></TR>
-->
<TR>
<!--<TD><script type="text/javascript" src="map/zillow_addr_history.php?addr=<?php echo $address ?>&city=<?php echo $city ?>&state=<?php echo $state ?>&zipcode=<?php echo $zipcode ?>"> </script></TD>
-->
<TD><script type="text/javascript" src="<?php echo SITE_ROOT_URL?>map/index_zip.php?zip=<?php echo $row["ZIPCODE"] ?>"> </script></TD>

<!--<TD><script type="text/javascript" src="map/prop_value_history.php?zpid=19791996"> </script></TD>
-->
<TD><script type="text/javascript" src="<?php echo SITE_ROOT_URL?>map/index_city.php?city=<?php echo $row["CITY"] ?>&state=<?php echo $row["STATE"] ?>"></script></TD>
<TD><script type="text/javascript" src="<?php echo SITE_ROOT_URL?>map/index_state.php?state=<?php echo $row["STATE"] ?>"> </script></TD>

</TR>
<TR>
<TD></TD>
<TD></TD>
<TD align="right">
<a target=_blank style=\"font-size:10px\" href='http://www.zillow.com/corp/Terms.htm'>Subject to Zillow Terms of Use</a></TD>
<?
}
?>

</TR>
</TABLE>
</div>
	<div>
	<?php 
	if($disp_zcomps)
	{
	map_control($zipcode,''); 
	}
	?>
	</div>
<!--	<div>
	<table style="border:1px solid;" cellspacing="0" cellpadding="0">
	<tr><td colspan="6" style='font-size:12px; font-weight:bold;' align='left'>Data provided by Zillow &copy; Zillow, Inc., 2006.</td><td><a href="http://www.zillow.com" title="Zillow"><img src="/images/other_logos/zillowlogo_150x40.gif" alt="Powered By Zillow"/></a></td></tr>
	<tr><td align="left">Use is subject to <a href='http://www.zillow.com/corp/Terms.htm' title='Terms of Use'>Terms of Use</a>.</td></tr>
	<tr><td align="left">What's a <a href='http://www.zillow.com/howto/Zestimate.htm' title='What is a Zestimate'>Zestimate</a>?</td></tr>
	<tr><td align="left">What's a <a href='http://www.zillow.com/howto/Zindex.htm' title='Zindex'>Zindex</a>?</li></td></tr>
	</table>
	</div>
-->	

<?php
if($disp_zesti || $disp_zcomps || $disp_zindex)
{
?>
<div class="realiventbrand" align="left">
<h2>Comparables and Value Estimate Data provided by Zillow</h2><h3>&copy; Zillow, Inc., 2006.</h3><a href="http://www.zillow.com" title="Zillow"><img src="/images/other_logos/zillow.gif" alt="Powered By Zillow" align="right" border="0"/></a>
<ul>
  <li style="font-size:9px">Use is subject to <a href='http://www.zillow.com/corp/Terms.htm' title='Terms of Use'>Terms of Use</a>.</li>
  <li style="font-size:9px">What's a <a href='http://www.zillow.com/howto/Zestimate.htm' title='What is a Zestimate'>Zestimate</a>?</li>
</ul>
</div>	
<?
}
?>

	</TD>
	
  </TR>
  
		
	
</table>


</td>
  </tr>
</table>